package com.dragon.client.controller.website;

import com.dragon.common.model.Insert;
import com.dragon.common.model.ResponseData;
import com.dragon.common.model.Update;
import com.dragon.logical.service.website.IDisplayPostsService;
import com.dragon.repository.domain.dto.DisplayPostsDTO;
import com.dragon.repository.domain.vo.DisplayPostsVO;
import com.dragon.repository.entity.DisplayPosts;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 热门职位展示 前端控制器
 * </p>
 *
 * @author sy
 * @since 2024-03-06
 */
@RestController
@RequestMapping("displayPosts")
@Api(tags = "热门岗位展示")
public class DisplayPostsController {

    @Autowired
    IDisplayPostsService service;

    @GetMapping("list")
    @ApiOperation(value = "材料列表")
    public ResponseData<List<DisplayPostsDTO>> exampleList(){
        List<DisplayPosts> displayPostsList = service.materialList();
        return ResponseData.success(DisplayPostsDTO.convertList(displayPostsList));
    }

    @PostMapping("add")
    @ApiOperation(value = "添加")
    public ResponseData exampleAdd(@RequestBody @Validated(Insert.class) DisplayPostsVO vo){
        service.postsAdd(DisplayPostsVO.convert(vo));
        return ResponseData.success();
    }

    @PostMapping("update")
    @ApiOperation(value = "修改")
    public ResponseData exampleUpdate(@RequestBody @Validated(Update.class) DisplayPostsVO vo){
        service.postsUpdate(DisplayPostsVO.convert(vo));
        return ResponseData.success();
    }

    @PostMapping("delete")
    @ApiOperation(value = "删除")
    public ResponseData exampleAdd(
            @ApiParam(name = "id", value = "id", readOnly = true, type = "int")
            @RequestParam Integer id
    ){
        service.postsDeleted(id);
        return ResponseData.success();
    }

}
